package com.jindy.module.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.product.domain.ProductModel;
import com.jindy.module.product.service.IProductModelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 型号Controller
 *
 * @author ruoyi
 * @date 2022-09-26
 */
@RestController
@RequestMapping("/module/model")
public class ProductModelController extends BaseController
{
    @Autowired
    private IProductModelService productModelService;

    /**
     * 查询型号列表
     */
//    @PreAuthorize("@ss.hasPermi('module:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductModel productModel)
    {
        startPage();
        List<ProductModel> list = productModelService.selectProductModelList(productModel);
        return getDataTable(list);
    }

    /**
     * 导出型号列表
     */
    @Log(title = "型号", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('module:model:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductModel productModel)
    {
        List<ProductModel> list = productModelService.selectProductModelList(productModel);
        ExcelUtil<ProductModel> util = new ExcelUtil<ProductModel>(ProductModel.class);
        util.exportExcel(response, list, "型号数据");
    }

    /**
     * 获取型号详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:model:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productModelService.selectProductModelById(id));
    }

    /**
     * 新增型号
     */
    @Log(title = "型号", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('module:model:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ProductModel productModel)
    {
        return toAjax(productModelService.insertProductModel(productModel));
    }

    /**
     * 修改型号
     */
    @Log(title = "型号", businessType = BusinessType.UPDATE)
//    @PreAuthorize("@ss.hasPermi('module:model:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody ProductModel productModel)
    {
        return toAjax(productModelService.updateProductModel(productModel));
    }

}
